package com.samsung.galaxy.database;

import java.util.ArrayList;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
import android.widget.Toast;

public class GalaxyDatabaseHandle extends SQLiteOpenHelper {

	Context mContext;

	private static final String DATABASE_NAME = "galaxyDatabase";
	private static final int DATABASE_VERSION = 1;

	// PROFILE TABLE NAME
	private static final String TABLE_PROFILE = "profiles";
	// PROFILE TABLE COLUMS NAME
	private static final String PROFILE_ID = "_id";
	private static final String PROFILE_ADDR = "address";
	private static final String PROFILE_BIRTH = "birthday";
	private static final String PROFILE_BOSS = "boss";
	private static final String PROFILE_COMPANY = "company";
	private static final String PROFILE_DESCRIPTION = "description";
	private static final String PROFILE_EMAIL = "email";
	private static final String PROFILE_FOLLOW = "follow";
	private static final String PROFILE_GROUP_ID = "groupid";
	private static final String PROFILE_HOBBY = "hobby";
	private static final String PROFILE_IMEI = "imei";
	private static final String PROFILE_IN_RELATIONSHIP = "inrelationship";
	private static final String PROFILE_INTERESTED_IN = "interested";
	private static final String PROFILE_LIKE = "like";
	private static final String PROFILE_PASS = "password";
	private static final String PROFILE_RELATIONSHIP = "relationship";
	private static final String PROFILE_SEX = "sex";
	private static final String PROFILE_STAR = "star";
	private static final String PROFILE_USERNAME = "username";

	// ALBUM TABLE NAME
	private static final String TABLE_ALBUM = "album";
	// Album tables colums name
	private static final String ALBUM_ID = "_id";
	private static final String ALBUM_NAME = "albumname";
	private static final String ALBUM_DATE = "date";
	private static final String ALBUM_NUMBER_IMAGE = "imagenumber";
	private static final String ALBUM_PERMISSION = "permission";

	// Image table name
	private static final String TABLE_IMAGE = "image";
	// Image table colums name
	private static final String IMAGE_ID = "_id";
	private static final String IMAGE_ALBUM_ID = "albumid";
	private static final String IMAGE_DESCRIPTION = "description";
	private static final String IMAGE_COMMENT_NUMBER = "commentnumber";
	private static final String IMAGE_DATE = "date";
	private static final String IMAGE_PATH = "imagepath";
	private static final String IMAGE_LIKE_NUMBER = "likenumber";
	private static final String IMAGE_PERMISSION = "permission";

	// Comment table name
	private static final String TABLE_COMMENT = "comment";
	// Comment table colums name
	private static final String COMMENT_ID = "_id";
	private static final String COMMENT_CONTENT = "content";
	private static final String COMMENT_DATE = "date";
	private static final String COMMENT_IMAGE_ID = "imageid";
	private static final String COMMENT_USER_ID = "userid";

	// Like table name
	private static final String TABLE_LIKE = "like";
	// Like table colums name
	private static final String LIKE_ID = "_id";
	private static final String LIKE_IMAGE_ID = "imageid";
	private static final String LIKE_USER_ID = "userid";
	private static final String LIKE_DATE = "date";

	// Group table name
	private static final String TABLE_GROUP = "_group";
	// Group table colums name
	private static final String GROUP_ID = "_id";
	private static final String GROUP_DATE = "date";
	private static final String GROUP_NAME = "groupname";
	private static final String GROUP_MEMBER_NUMBER = "membernumber";

	public GalaxyDatabaseHandle(Context context) {

		super(context, DATABASE_NAME, null, DATABASE_VERSION);
		mContext = context;

	}

	@Override
	public void onCreate(SQLiteDatabase db) {

		String CREATE_PROFILE_TABLE = "CREATE TABLE " + TABLE_PROFILE + "("
				+ PROFILE_ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"
				+ PROFILE_USERNAME + " TEXT," + PROFILE_SEX + " INTEGER,"
				+ PROFILE_BIRTH + " TEXT," + PROFILE_ADDR + " TEXT,"
				+ PROFILE_COMPANY + " TEXT," + PROFILE_DESCRIPTION + " TEXT,"
				+ PROFILE_EMAIL + " TEXT," + PROFILE_FOLLOW + " INTEGER,"
				+ PROFILE_LIKE + " INTEGER," + PROFILE_STAR + " INTEGER,"
				+ PROFILE_HOBBY + " TEXT," + PROFILE_INTERESTED_IN + " TEXT,"
				+ PROFILE_IN_RELATIONSHIP + " INTEGER," + PROFILE_RELATIONSHIP
				+ " INTEGER," + PROFILE_GROUP_ID + " INTEGER,"

				+ PROFILE_BOSS + " INTEGER," + PROFILE_IMEI + " TEXT,"
				+ PROFILE_PASS + " TEXT" + ")";
		Log.d("sql", CREATE_PROFILE_TABLE);

		db.execSQL(CREATE_PROFILE_TABLE);

		String CREATE_LIKE_TABLE = "CREATE TABLE " + TABLE_LIKE + "(" + LIKE_ID
				+ " INTEGER PRIMARY KEY AUTOINCREMENT," + LIKE_DATE + " TEXT,"
				+ LIKE_USER_ID + " INTEGER," + LIKE_IMAGE_ID + " INTEGER" + ")";
		db.execSQL(CREATE_LIKE_TABLE);

		String CREATE_IMAGE_TABLE = "CREATE TABLE " + TABLE_IMAGE + "("
				+ IMAGE_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + IMAGE_PATH
				+ " TEXT," + IMAGE_COMMENT_NUMBER + " INTEGER," + IMAGE_DATE
				+ " TEXT," + IMAGE_DESCRIPTION + " TEXT," + IMAGE_LIKE_NUMBER
				+ " INTEGER," + IMAGE_ALBUM_ID + " INTEGER," + IMAGE_PERMISSION
				+ " INTEGER" + ")";
		db.execSQL(CREATE_IMAGE_TABLE);

		String CREATE_GROUP_TABLE = "CREATE TABLE " + TABLE_GROUP + "("
				+ GROUP_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + GROUP_DATE
				+ " TEXT," + GROUP_MEMBER_NUMBER + " INTEGER," + GROUP_NAME
				+ " TEXT" + ")";
		Log.d("sql", CREATE_GROUP_TABLE);
		db.execSQL(CREATE_GROUP_TABLE);

		String CREATE_COMMENT_TABLE = "CREATE TABLE " + TABLE_COMMENT + "("
				+ COMMENT_ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"
				+ COMMENT_IMAGE_ID + " INTEGER," + COMMENT_USER_ID
				+ " INTEGER," + COMMENT_CONTENT + " TEXT," + COMMENT_DATE
				+ " TEXT" + ")";
		db.execSQL(CREATE_COMMENT_TABLE);

		String CREATE_ALBUM_TABLE = "CREATE TABLE " + TABLE_ALBUM + "("
				+ ALBUM_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + ALBUM_DATE
				+ " TEXT," + ALBUM_NAME + " TEXT," + ALBUM_NUMBER_IMAGE
				+ " INTEGER," + ALBUM_PERMISSION + " INTEGER" + ")";
		db.execSQL(CREATE_ALBUM_TABLE);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// TODO Auto-generated method stub
		db.execSQL("drop table if exists " + TABLE_ALBUM);
		db.execSQL("drop table if exists " + TABLE_COMMENT);
		db.execSQL("drop table if exists " + TABLE_GROUP);
		db.execSQL("drop table if exists " + TABLE_IMAGE);
		db.execSQL("drop table if exists " + TABLE_LIKE);
		db.execSQL("drop table if exists " + TABLE_PROFILE);
		onCreate(db);

	}

	/*-------------------------- ADD FUNCTION--------------------------*/

	// add new group
	public void addGroup(Group group) {

		SQLiteDatabase mdb = getWritableDatabase();
		ContentValues mValue = new ContentValues();

		// mValue.put(GROUP_DATE, group.getDate());
		mValue.put(GROUP_NAME, group.getGroupName());
		mValue.put(GROUP_MEMBER_NUMBER, group.getNumberOfMembers());

		mdb.insert(TABLE_GROUP, null, mValue);
		mdb.close();
	}

	// addfriend
	// them mot ban ghi vao bang profile
	public void addNewFriend(User user) {

		SQLiteDatabase mdb = getWritableDatabase();
		ContentValues mValue = new ContentValues();

		mValue.put(PROFILE_ADDR, user.getAddress());
		mValue.put(PROFILE_LIKE, user.getLike());
		mValue.put(PROFILE_BIRTH, user.getBirthday());
		mValue.put(PROFILE_COMPANY, user.getCompany());
		mValue.put(PROFILE_DESCRIPTION, user.getDescription());
		mValue.put(PROFILE_EMAIL, user.getEmail());
		mValue.put(PROFILE_FOLLOW, user.getFollow());
		mValue.put(PROFILE_IMEI, user.getImei());
		mValue.put(PROFILE_IN_RELATIONSHIP, user.getInRelationship());
		mValue.put(PROFILE_RELATIONSHIP, user.getRelationship());
		mValue.put(PROFILE_SEX, user.getSex());
		mValue.put(PROFILE_STAR, user.getStar());
		mValue.put(PROFILE_BOSS, user.getBoss());
		mValue.put(PROFILE_GROUP_ID, user.getGroupId());
		mValue.put(PROFILE_USERNAME, user.getUsername());
		if (user.getHobby().length > 0) {
			for (int i = 0; i < user.getHobby().length; i++) {
				mValue.put(PROFILE_HOBBY, user.getHobby()[i]);
			}
		}

		if (user.getInterestedIn().length > 0) {
			for (int i = 0; i < user.getInterestedIn().length; i++) {
				mValue.put(PROFILE_INTERESTED_IN, user.getInterestedIn()[i]);
			}
		}

		mdb.insert(TABLE_PROFILE, null, mValue);
		mdb.close();

	}

	// add new an album
	public void addAlbum(Album album) {

		SQLiteDatabase mdb = getWritableDatabase();
		ContentValues mValue = new ContentValues();

		// mValue.put(ALBUM_DATE, album.getDate());
		mValue.put(ALBUM_NAME, album.getAlbumName());
		mValue.put(ALBUM_NUMBER_IMAGE, album.getNumberOfImage());
		mValue.put(ALBUM_PERMISSION, album.getPermission());

		mdb.insert(TABLE_ALBUM, null, mValue);
		mdb.close();
	}

	// add new an image and update into Album table
	public void addImage(Image image, Album album) {

		SQLiteDatabase mdb = getWritableDatabase();
		ContentValues mValue = new ContentValues();

		mValue.put(IMAGE_LIKE_NUMBER, image.getLike());
		mValue.put(IMAGE_ALBUM_ID, image.getAlbumId());
		// mValue.put(IMAGE_DATE, image.getDate());
		mValue.put(IMAGE_DESCRIPTION, image.getDescription());
		mValue.put(IMAGE_COMMENT_NUMBER, image.getComment());
		mValue.put(IMAGE_PATH, image.getImagePath());
		mValue.put(IMAGE_PERMISSION, image.getPermissionId());

		mValue.put(ALBUM_NUMBER_IMAGE, album.getNumberOfImage() + 1);

		mdb.update(TABLE_ALBUM, mValue, ALBUM_ID + " = ?",
				new String[] { String.valueOf(image.getAlbumId()) });
		mdb.insert(TABLE_IMAGE, null, mValue);
		mdb.close();
	}

	// add new comment
	public void addComment(Comment cmt) {

		SQLiteDatabase mdb = getWritableDatabase();
		ContentValues mValue = new ContentValues();

		mValue.put(COMMENT_CONTENT, cmt.getContent());
		mValue.put(COMMENT_IMAGE_ID, cmt.getImageId());
		mValue.put(COMMENT_USER_ID, cmt.getUserId());
		// mValue.put(COMMENT_DATE, cmt.getDate());

		mdb.insert(TABLE_COMMENT, null, mValue);
		mdb.close();

	}

	// add a new comment and update into image table
	public void addComment(User user, Image img, String content) {

		SQLiteDatabase mdb = getWritableDatabase();
		ContentValues mValue = new ContentValues();

		mValue.put(COMMENT_CONTENT, content);
		mValue.put(COMMENT_IMAGE_ID, img.getImageId());
		mValue.put(COMMENT_USER_ID, user.getUserId());
		// mValue.put(COMMENT_DATE, cmt.getDate());
		mValue.put(IMAGE_COMMENT_NUMBER, img.getComment() + 1);

		mdb.update(TABLE_IMAGE, mValue, IMAGE_ID + " = ?",
				new String[] { String.valueOf(img.getImageId()) });
		mdb.insert(TABLE_COMMENT, null, mValue);
		mdb.close();

	}

	// new Like
	public void addLike(Like like) {

		SQLiteDatabase mdb = getWritableDatabase();
		ContentValues mValue = new ContentValues();

		mValue.put(LIKE_IMAGE_ID, like.getImageId());
		mValue.put(LIKE_USER_ID, like.getUserId());
		// mValue.put(LIKE_DATE, like.getDate());

		mdb.insert(TABLE_LIKE, null, mValue);
		mdb.close();

	}

	// add a new like and update into image table
	public void addLike(User user, Image img) {

		SQLiteDatabase mdb = getWritableDatabase();
		ContentValues mValue = new ContentValues();

		mValue.put(LIKE_IMAGE_ID, img.getImageId());
		mValue.put(LIKE_USER_ID, user.getUserId());
		mValue.put(IMAGE_LIKE_NUMBER, img.getLike() + 1);
		// mValue.put(LIKE_DATE, like.getDate());

		mdb.insert(TABLE_LIKE, null, mValue);
		mdb.update(TABLE_IMAGE, mValue, IMAGE_ID + " = ? ",
				new String[] { String.valueOf(img.getImageId()) });
		mdb.close();

	}

	/*-------------------------- INSERT - UPDATE FUNCTION--------------------------*/
	/*
	 * update infomation or update profile
	 */
	// update info include : like - follow - star - relationship -
	// inrelationship
	public void updateInfo(User user) {

		SQLiteDatabase mdb = getWritableDatabase();
		ContentValues mValue = new ContentValues();

		mValue.put(PROFILE_LIKE, user.getLike());
		mValue.put(PROFILE_FOLLOW, user.getFollow());
		mValue.put(PROFILE_IN_RELATIONSHIP, user.getInRelationship());
		mValue.put(PROFILE_RELATIONSHIP, user.getRelationship());
		mValue.put(PROFILE_STAR, user.getStar());
		mValue.put(PROFILE_USERNAME, user.getUsername());
		if (user.getHobby().length > 0) {
			for (int i = 0; i < user.getHobby().length; i++) {
				mValue.put(PROFILE_HOBBY, user.getHobby()[i]);
			}
		}

		if (user.getInterestedIn().length > 0) {
			for (int i = 0; i < user.getInterestedIn().length; i++) {
				mValue.put(PROFILE_INTERESTED_IN, user.getInterestedIn()[i]);
			}
		}

		mdb.update(TABLE_PROFILE, mValue, PROFILE_ID + " = ?",
				new String[] { String.valueOf(user.getUserId()) });
		mdb.close();

	}

	// update basic info include : address - company - birthday - email -
	// description - sex
	public void updateBasicInfo(User user) {

		SQLiteDatabase mdb = getWritableDatabase();
		ContentValues mValue = new ContentValues();

		mValue.put(PROFILE_ADDR, user.getAddress());
		mValue.put(PROFILE_BIRTH, user.getBirthday());
		mValue.put(PROFILE_COMPANY, user.getCompany());
		mValue.put(PROFILE_DESCRIPTION, user.getDescription());
		mValue.put(PROFILE_EMAIL, user.getEmail());
		mValue.put(PROFILE_IMEI, user.getImei());
		mValue.put(PROFILE_SEX, user.getSex());

		mdb.update(TABLE_PROFILE, mValue, PROFILE_ID + " = ?",
				new String[] { String.valueOf(user.getUserId()) });
		mdb.close();

	}

	// update advanced info include : hobby - interested -
	public void updateAdvancedInfo(User user) {

		SQLiteDatabase mdb = getWritableDatabase();
		ContentValues mValue = new ContentValues();

		if (user.getHobby().length > 0) {
			for (int i = 0; i < user.getHobby().length; i++) {
				mValue.put(PROFILE_HOBBY, user.getHobby()[i]);
			}
		}

		if (user.getInterestedIn().length > 0) {
			for (int i = 0; i < user.getInterestedIn().length; i++) {
				mValue.put(PROFILE_INTERESTED_IN, user.getInterestedIn()[i]);
			}
		}

		mdb.update(TABLE_PROFILE, mValue, PROFILE_ID + " = ?",
				new String[] { String.valueOf(user.getUserId()) });
		mdb.close();
	}

	// edit Album info : permission and album name
	public void editAlbum(Album album) {

		SQLiteDatabase mdb = getWritableDatabase();
		ContentValues mValue = new ContentValues();

		mValue.put(ALBUM_NAME, album.getAlbumName());
		mValue.put(ALBUM_PERMISSION, album.getPermission());

		mdb.update(TABLE_ALBUM, mValue, ALBUM_ID + " = ?",
				new String[] { String.valueOf(album.getAlbumId()) });
		mdb.close();
	}

	// update Album info while change permission
	public void updateAlbumPermission(Album album) {

		SQLiteDatabase mdb = getWritableDatabase();
		ContentValues mValue = new ContentValues();

		mValue.put(ALBUM_PERMISSION, album.getPermission());

		mdb.update(TABLE_ALBUM, mValue, ALBUM_ID + " = ?",
				new String[] { String.valueOf(album.getAlbumId()) });
		mdb.close();

	}

	// update Album info when change Album Name
	public void updateAlbumName(Album album) {

		SQLiteDatabase mdb = getWritableDatabase();
		ContentValues mValue = new ContentValues();

		mValue.put(ALBUM_NAME, album.getAlbumName());

		mdb.update(TABLE_ALBUM, mValue, ALBUM_ID + " = ?",
				new String[] { String.valueOf(album.getAlbumId()) });
		mdb.close();
	}

	// move Image between 2 Album
	public void moveOneImage(Image image, Album oldAlbum, Album newAlbum) {

		SQLiteDatabase mdb = getWritableDatabase();
		ContentValues mValue = new ContentValues();
		ContentValues mValue2 = new ContentValues();

		mValue.put(IMAGE_ALBUM_ID, newAlbum.getAlbumId());
		mValue.put(ALBUM_NUMBER_IMAGE, oldAlbum.getNumberOfImage() - 1);
		mValue2.put(ALBUM_NUMBER_IMAGE, newAlbum.getNumberOfImage() + 1);

		mdb.update(TABLE_IMAGE, mValue, IMAGE_ID + " = ?",
				new String[] { String.valueOf(image.getImageId()) });
		mdb.update(TABLE_ALBUM, mValue, ALBUM_ID + "= ?",
				new String[] { String.valueOf(oldAlbum.getAlbumId()) });
		mdb.update(TABLE_ALBUM, mValue2, ALBUM_ID + "= ?",
				new String[] { String.valueOf(newAlbum.getAlbumId()) });

		mValue.clear();

		mdb.close();

	}

	// move multi Images
	public void moveMultiImages(Image[] image, Album oldAlbum, Album newAlbum) {

	}

	// edit Image info : permission and description
	public void editImage(Image img) {

		SQLiteDatabase mdb = getWritableDatabase();
		ContentValues mValue = new ContentValues();

		// mValue.put(IMAGE_ALBUM_ID, img.getAlbumId());
		mValue.put(IMAGE_PERMISSION, img.getPermissionId());
		mValue.put(IMAGE_DESCRIPTION, img.getDescription());

		mdb.update(TABLE_IMAGE, mValue, IMAGE_ID + " = ?",
				new String[] { String.valueOf(img.getImageId()) });
		mdb.close();

	}

	// edit image description
	public void editImageDescription(Image img, String description) {

		SQLiteDatabase mdb = getWritableDatabase();
		ContentValues mValue = new ContentValues();

		mValue.put(IMAGE_DESCRIPTION, description);

		mdb.update(TABLE_IMAGE, mValue, IMAGE_ID + " = ?",
				new String[] { String.valueOf(img.getImageId()) });
		mdb.close();
	}

	// edit image permission
	public void editImagePermission(Image img, int permission) {
		SQLiteDatabase mdb = getWritableDatabase();
		ContentValues mValue = new ContentValues();

		mValue.put(IMAGE_PERMISSION, permission);

		mdb.update(TABLE_IMAGE, mValue, IMAGE_ID + " = ?",
				new String[] { String.valueOf(img.getImageId()) });
		mdb.close();
	}

	/*
	 * // update Image info - using when new comment, new like public void
	 * updateImage(Image img) {
	 * 
	 * SQLiteDatabase mdb = getWritableDatabase(); ContentValues mValue = new
	 * ContentValues();
	 * 
	 * mValue.put(IMAGE_LIKE_NUMBER, img.getLike());
	 * mValue.put(IMAGE_COMMENT_NUMBER, img.getComment());
	 * 
	 * mdb.update(TABLE_IMAGE, mValue, IMAGE_ID + " = ?", new String[] {
	 * String.valueOf(img.getImageId()) }); mdb.close();
	 * 
	 * }
	 */

	/*
	 * // update like image - using when another user like an image public void
	 * updateLikeImage(Image img) {
	 * 
	 * SQLiteDatabase mdb = getWritableDatabase(); ContentValues mValue = new
	 * ContentValues();
	 * 
	 * mValue.put(IMAGE_LIKE_NUMBER, img.getLike());
	 * mValue.put(IMAGE_COMMENT_NUMBER, img.getComment());
	 * 
	 * mdb.update(TABLE_IMAGE, mValue, IMAGE_ID + " = ?", new String[] {
	 * String.valueOf(img.getImageId()) }); mdb.close();
	 * 
	 * }
	 */

	// edit Group info - only name
	public void editGroup(Group group, String name) {

		SQLiteDatabase mdb = getWritableDatabase();
		ContentValues mValue = new ContentValues();

		mValue.put(GROUP_NAME, name);

		mdb.update(TABLE_GROUP, mValue, GROUP_ID + " = ?",
				new String[] { String.valueOf(group.getGroupName()) });
		mdb.close();
	}

	// move user between 2 groups
	public void moveUser(User user, Group oldGroup, Group newGroup) {

		SQLiteDatabase mdb = getWritableDatabase();
		ContentValues mValue = new ContentValues();

		mValue.put(PROFILE_GROUP_ID, newGroup.getGroupId());
		mdb.update(TABLE_PROFILE, mValue, PROFILE_ID + " = ?",
				new String[] { String.valueOf(user.getUserId()) });
		mValue.clear();

		mValue.put(GROUP_MEMBER_NUMBER, newGroup.getNumberOfMembers() + 1);
		mdb.update(TABLE_GROUP, mValue, GROUP_ID + " = ?",
				new String[] { String.valueOf(newGroup.getGroupId()) });
		mValue.clear();

		mValue.put(GROUP_MEMBER_NUMBER, oldGroup.getNumberOfMembers() - 1);
		mdb.update(TABLE_GROUP, mValue, GROUP_ID + " = ?",
				new String[] { String.valueOf(oldGroup.getGroupId()) });
		mValue.clear();

		mdb.close();
	}

	// edit content of comment
	public void editComment(Comment comment, String content) {

		SQLiteDatabase mdb = getWritableDatabase();
		ContentValues mValue = new ContentValues();

		mValue.put(COMMENT_CONTENT, content);

		mdb.update(TABLE_COMMENT, mValue, COMMENT_ID + " = ?",
				new String[] { String.valueOf(comment.getCommentId()) });

		mdb.close();
	}

	/*-------------------------- QUERY FUNCTION--------------------------*/

	// get information of a user
	public User getUserInfo(int id) {

		SQLiteDatabase mdb = getReadableDatabase();
		Cursor mCursor = mdb.query(TABLE_PROFILE, null, PROFILE_ID + " = ?",
				new String[] { String.valueOf(id) }, PROFILE_GROUP_ID, null,
				PROFILE_USERNAME);

		if (mCursor != null) {
			mCursor.moveToFirst();
		}
		User mUser = new User(mCursor.getString(1), Integer.parseInt(mCursor
				.getString(2)), mCursor.getString(3), mCursor.getString(4),
				mCursor.getString(5), mCursor.getString(6),
				mCursor.getString(7), Integer.parseInt(mCursor.getString(8)),
				Integer.parseInt(mCursor.getString(9)),
				Integer.parseInt(mCursor.getString(10)),
				new String[] { mCursor.getString(11) },
				new String[] { mCursor.getString(12) },
				Integer.parseInt(mCursor.getString(13)),
				Integer.parseInt(mCursor.getString(14)),
				Integer.parseInt(mCursor.getString(15)),
				Integer.parseInt(mCursor.getString(16)), mCursor.getString(17),
				null);

		Toast.makeText(mContext, "information of user", Toast.LENGTH_LONG)
				.show();
		mCursor.close();
		mdb.close();
		return mUser;
	}

	// getAll Friends
	public ArrayList<User> getAllFriend() {

		SQLiteDatabase mdb = getReadableDatabase();
		String sql = "Select * from " + TABLE_PROFILE;// + "where" + PROFILE_ID
														// + " != 1";
		Cursor mCursor = mdb.rawQuery(sql, null);

		ArrayList<User> myArray = new ArrayList<User>();
		if (mCursor.moveToFirst()) {
			do {
				myArray.add(new User(mCursor.getString(1), Integer
						.parseInt(mCursor.getString(2)), mCursor.getString(3),
						mCursor.getString(4), mCursor.getString(5), mCursor
								.getString(6), mCursor.getString(7), Integer
								.parseInt(mCursor.getString(8)), Integer
								.parseInt(mCursor.getString(9)), Integer
								.parseInt(mCursor.getString(10)),
						new String[] { mCursor.getString(11) },
						new String[] { mCursor.getString(12) }, Integer
								.parseInt(mCursor.getString(13)), Integer
								.parseInt(mCursor.getString(14)), Integer
								.parseInt(mCursor.getString(15)), Integer
								.parseInt(mCursor.getString(16)), mCursor
								.getString(17), null));
			} while (mCursor.moveToNext());
		}
		mCursor.close();
		mdb.close();
		return myArray;
	}

	/*-------------------------- DELETE FUNCTION--------------------------*/

	// delete User
	public void deleteUser(User user) {

		SQLiteDatabase mdb = getWritableDatabase();
		mdb.delete(TABLE_PROFILE, PROFILE_ID + " = ?",
				new String[] { String.valueOf(user.getUserId()) });

	}

	public void deleteUser(int id) {

		SQLiteDatabase mdb = getWritableDatabase();
		mdb.delete(TABLE_PROFILE, PROFILE_ID + " = ?",
				new String[] { String.valueOf(id) });

	}

	// deleta an image
	public void deleteImage(Image image) {

		SQLiteDatabase mdb = getWritableDatabase();
		ContentValues mValue = new ContentValues();

		// mValue.put(ALBUM_NUMBER_IMAGE, value) // thieu truy van updade vao
		// album_number_image
		mdb.delete(TABLE_IMAGE, IMAGE_ID + " = ?",
				new String[] { String.valueOf(image.getImageId()) });
		mdb.delete(TABLE_COMMENT, COMMENT_IMAGE_ID + " = ?",
				new String[] { String.valueOf(image.getImageId()) });
		mdb.delete(TABLE_LIKE, LIKE_IMAGE_ID + " = ?",
				new String[] { String.valueOf(image.getImageId()) });

	}

	// delete an Album
	public void deleteAlbum(Album album) {

		SQLiteDatabase mdb = getWritableDatabase();

		// mdb.delete(TABLE_COMMENT, whereClause, whereArgs)
	}
}
